package com.lsy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lsy.entity.User;
import com.lsy.response.Result;
import com.lsy.response.ResultCode;
import com.lsy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 * @description UserController
 * @date 2022-03-11 10:19
 */
@RestController
@RequestMapping(value = "/api")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 校验用户是否已存在
     * @param username
     * @return
     */
    @GetMapping(value = "/ckusr")
    public Result checkUser(String username) {

        if(StringUtils.isEmpty(username)){
            return Result.error(ResultCode.PARAM_IS_BLANK);
        }
        //判断用户是否存在
        LambdaQueryWrapper<User> querywrapper =new LambdaQueryWrapper<User>();
        querywrapper.eq(User::getUserName, username);

        User user=userService.getOne(querywrapper);
        if(user==null){
            return Result.error(ResultCode.USER_ACCOUNT_ALREADY_EXIST);
        }

        return Result.ok();
    }
}
